package net.xdclass.config;

import jakarta.annotation.Resource;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.util.concurrent.*;

/**
 * @author 小二
 */
@Configuration
public class FileUploadExecutor {

    @Resource
    private ThreadPoolExecutorConfig threadPoolExecutorConfig;
    @Bean
    public ExecutorService getExecutorService() {
        ExecutorService executorService = new ThreadPoolExecutor(
                threadPoolExecutorConfig.getCorePoolSize(),
                threadPoolExecutorConfig.getMaxPoolSize(),
                threadPoolExecutorConfig.getKeepAliveSeconds(),
                TimeUnit.SECONDS,
                new LinkedBlockingQueue<>(threadPoolExecutorConfig.getQueueCapacity()),
                Executors.defaultThreadFactory(),
                new ThreadPoolExecutor.AbortPolicy()
        );
        return executorService;
    }

}
